﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP.Classes;
using ERP.View;
using ERP.Reports;
using ERP.Hoadon;

namespace ERP.Hoadon
{
    public partial class viewERP_CanhbaoMay : DevExpress.XtraEditors.XtraForm
    {
        public cs_hmr_usersInfo user = new cs_hmr_usersInfo();
        public int flag = 0;
        public int count = 0;
        public cs_erp_hoadonInfo hoadon = new cs_erp_hoadonInfo();

        public viewERP_CanhbaoMay()
        {
            InitializeComponent();
        }

        private void viewERP_CanhbaoMay_Load(object sender, EventArgs e)
        {
            this.Load_Data(1);
        }
        private void Load_Data(int opt)
        {
            DataSet ds = new DataSet("ds");
            ds = this.hoadon.Get_List_Canhbao(opt);
            if (ds == null || ds.Tables[0].Rows.Count == 0)
            {
                this.count = 0;
            }
            else
            {
                this.count = ds.Tables[0].Rows.Count;
                this.grcDanhsach.DataSource = ds.Tables[0];
                this.gridView1.ExpandAllGroups();
            }
        }

        private void btnChitietHD_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            this.Load_Data(1);
        }

        private void btnDieuchinh_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            this.Load_Data(2);
        }

        private void btnIn_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            if (this.count > 0 && this.gridView1.FocusedRowHandle >= 0 && this.gridView1.FocusedRowHandle <= this.count)
            {
                this.hoadon.id_hd = Convert.ToInt32(this.gridView1.GetRowCellValue(this.gridView1.FocusedRowHandle, this.grdcID));
                if (this.hoadon.Get_Info() > 0)
                {
                    viewERP_NhapHoadon nhd = new viewERP_NhapHoadon();
                    nhd.user = this.user;
                    nhd.flag = 3;
                    nhd.hoadon = this.hoadon;
                    nhd.MdiParent = this.MdiParent;
                    nhd.Show();
                }
            }
        }

        private void btnThoat_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            this.Dispose(true);
        }
    }
}